﻿Imports DataObject
Imports BusinessObject
Imports Microsoft.ApplicationBlocks.Data

Public Class frmChucDanhList

    Private oChucDanh As New BusChucDanh
    Private oPrChucDanh As New ChucDanh
    Private oConn As New hDBase

    Private Sub frmChucDanhList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitData()
        LoadGridView()
        RefreshToolbar()
    End Sub

    Protected Overrides Sub LoadDataGrid()
        Try
            tableDictionary = oChucDanh.GetAllChucDanh(sConn)
            ListBindingSource.DataSource = tableDictionary
            grdList.DataSource = ListBindingSource
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub LoadGridView()
        Try
            grdList.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect
            With grdList.DisplayLayout.Bands(0)
                .Columns("SoChucDanh").Hidden = True
                .Columns("MaChucDanh").Header.Caption = "Mã chức danh"
                .Columns("TenChucDanh").Header.Caption = "Tên chức danh"
                .Columns("DienGiai").Header.Caption = "Diễn giải"
                .Columns("HoatDong").Header.Caption = "Đang sử dụng"

                .Columns("MaChucDanh").Width = 50
                .Columns("TenChucDanh").Width = 100
            End With
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
       
    End Sub

    Protected Overrides Sub InitAddNewRow(ByVal oRow As System.Data.DataRow)
        With oRow
            .Item("MaChucDanh") = ""
            .Item("TenChucDanh") = ""
            .Item("DienGiai") = ""
            .Item("HoatDong") = True
        End With
    End Sub

    Protected Overrides Function DeleteDictionary() As Boolean
        oPrChucDanh.SoChucDanh = iValue
        oChucDanh.DeleteChucDanh(sConn, oPrChucDanh)
    End Function

    Private Sub grdList_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdList.MouseClick
        Try
            iValue = grdList.ActiveRow.Cells(TablePrimaryKey).Value
        Catch ex As Exception
        End Try
    End Sub

End Class
